/**
  HJ64 MP3光标位置。
*/
// const readline = require('readline')
// const rl = readline.createInterface({
//   input:process.stdin,
//   output:process.stdout
// })


function transform(input, setpActive) {
  setpActive = setpActive.toUpperCase().split('')
  const playerList = []
  for(let i = 1; i <= input; i++) { playerList.push(i) }
  let currentList = playerList.slice(0, 4)
  let current = 0
  let playerListCur = 0
  function computerPlayer(handler) {
    if (current < 0) { // 到最后一条，刷新播放列表
      currentList = playerList.slice(playerList.length - 4, playerList.length)
      current = playerList.length - 1
      playerListCur = 3
    } else if (current == playerList.length) {
      current = 0
      playerListCur = 0
      currentList = playerList.slice(0, 4)
    } else if (playerListCur < 0) { // 当前播放列表到第一条
      playerListCur = 0
      currentList = playerList.slice(current, current + 4)
    } else if (playerListCur > 3) { // 当前播放到第四
      playerListCur = 3
      currentList = playerList.slice(current - 3, current + 1)
    }
    // console.log(currentList.join(' '))
    // console.log(handler)
    // console.log(current)
  }
  setpActive.forEach((handler, idx) => {
    switch (handler) {
      case 'U':
        current--
        playerListCur--
        break
      case 'D':
        current++
        playerListCur++
        break
    }
    if (idx === 14) debugger
    computerPlayer(handler)
  })
  console.log(currentList.join(' '))
  console.log(playerList[current])
}

// 本地测试
let input = 83
let setpActive = 'UUDUDDDDUDUUDDDDUDD'
transform(input, setpActive)

// U 

// let inputArr = []
// 提交测试
// rl.on('line', (line) => {
//   inputArr.push(line)
//   if(inputArr.length === 2) { transform(parseInt(inputArr[0]), inputArr[1]) }
// })